#include "StdAfx.h"
#include "MVanillaEmpOptionPricer.h"
#include <exception>

namespace TreasAlgo
{

MVanillaEmpOptionPricer::MVanillaEmpOptionPricer()
	: m_optPtr(new TsVanillaEmpOptionPricer())
{
}

MVanillaEmpOptionPricer::~MVanillaEmpOptionPricer()
{	
}

void MVanillaEmpOptionPricer::priceOption(
						DateTime	valueDate,
						DateTime	maturity,
						DateTime	vestStartDate,
						double		underlying,
						double		strike,
						double		riskFreeRate,
						double		dividendYield,
						double		empLossRate,
						double		volatility,
						double%		NPV,
						double%		delta,
						double%		gamma,
						double%		theta)
{
	try
	{
		Date valDate((int)valueDate.ToOADate());
		Date matDate((int)maturity.ToOADate());
		Date vestDate((int)vestStartDate.ToOADate());

		double nVal = NPV;
		double dVal = delta;
		double gVal = gamma;
		double tVal = theta;

		m_optPtr->priceOption(valDate,
							  matDate,
							  vestDate,
							  underlying,
							  strike,
							  riskFreeRate,
							  dividendYield,
							  empLossRate,
							  volatility,
							  nVal,
							  dVal,
							  gVal,
							  tVal);

		NPV = nVal;
		delta = dVal;
		gamma = gVal;
		theta = tVal;
	}
	catch(const std::exception & ex)
	{
		String ^errorMessage = String::Format(L"Exception thrown while pricing vanilla employee option: {0}", gcnew String(ex.what()));
		throw gcnew Exception(errorMessage);
	}
	catch(Exception ^e)
	{
		throw e;
	}
	catch(...)
	{
		throw gcnew Exception("Unexpected failure while calculating vanilla employee option price.");
	}
}

}

